﻿using Cart.SanPhamSrv;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

namespace Cart
{
    public partial class PopupNoiDungCT : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            if (Session["IdSanPham"] != null)
            {
                using (var spService = new SanPhamSrv.SanPhamServiceClient())
                {
                    var modelsanpham = spService.ChiTietSanPham(Convert.ToInt64(Session["IdSanPham"]));
                    lbLoai.InnerText = modelsanpham.Ten.ToUpper();
                }
            }
        }

        protected void register_button1_Click(object sender, EventArgs e)
        {
            using (var spService = new SanPhamSrv.SanPhamServiceClient())
            {
                if ( Session["IdSanPham"] != null)
                {
                var spct = new SanPhamNoiDungCT();
                spct.IdSanPham = Convert.ToInt64(Session["IdSanPham"]);
                spct.NoiDung = txtHoTen.Text;
                var result = spService.CapNhatSanPhamChiTiet(null, spct);
                ClientScript.RegisterStartupScript(this.GetType(), "alert", "<script>alert('" + result + "');</script>");
                Page.ClientScript.RegisterStartupScript(this.GetType(), "close", "window.close();if (window.opener && !window.opener.closed) {window.opener.location.reload();}", true);
                }
                ClientScript.RegisterStartupScript(this.GetType(), "alert", "<script>alert('Không lấy được dữ liệu sản phẩm');</script>"); 
                Page.ClientScript.RegisterStartupScript(this.GetType(), "close", "window.close();", true);
            }
        }
    }
}